package com.hw.common.bean;


import com.hw.common.utils.StringUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.Locale;


/*****
 * <pre>
 * 类名称：RequestBean
 * 类描述：服务请求基础类
 * 创建人：JokenWang
 * 创建时间：2015年5月15日 下午1:59:10
 * 修改人：
 * 修改时间：
 * </pre>
 * 
 * @version 1.0.0
 */
public class RequestBean implements Serializable
{
    private static final long serialVersionUID = 296968876446221098L;
    
    /**
     * 访问来源，目前有WEB(3),Android(2),IOS(1)
     */
    private String channel;
    
    /**
     * 加密方式，不区分大小写
     * 加密:simple
     * 不加密:none
     * 默认为none
     */
    private String encrypt;
    
    /**
     * 页数
     */
    @Pattern(regexp = "\\d+", message = "pageNo必须是正整数")
    @Max(value = 999999, message = "pageNo最大为999999")
    @Min(value = 1, message = "pageNo最小为1")
    private String pageNo;
    
    /**
     * 每页条数
     */
    @Pattern(regexp = "\\d+", message = "pageNo必须是正整数")
    @Max(value = 50, message = "pageSize最大为50")
    @Min(value = 1, message = "pageSize最小为10")
    private String pageSize;
    
    private String locale;
    
    /*****
     * @version 1.0.0
     * @return locale
     */
    public Locale getLocale()
    {
        if (StringUtils.isBlank(locale))
        {
            locale = "zh_CN";
        }
        locale = locale.trim();
        Locale getLocale = org.springframework.util.StringUtils.parseLocaleString(locale);
        return getLocale;
    }
    
    /*****
     * @param locale
     * @version 1.0.0
     */
    public void setLocale(String locale)
    {
        this.locale = locale;
    }
    
    /*****
     * @version 1.0.0
     * @return pageNo 页数
     */
    public String getPageNo()
    {
        return pageNo;
    }
    
    /*****
     * @param pageNo
     *            页数
     * @version 1.0.0
     */
    public void setPageNo(String pageNo)
    {
        this.pageNo = pageNo;
    }
    
    /*****
     * @version 1.0.0
     * @return pageSize 每页条数
     */
    public String getPageSize()
    {
        return pageSize;
    }
    
    /*****
     * @param pageSize
     *            每页条数
     * @version 1.0.0
     */
    public void setPageSize(String pageSize)
    {
        this.pageSize = pageSize;
    }
    
    /*****
     * @version 1.0.0
     * @return encrypt
     */
    public final String getEncrypt()
    {
        return encrypt;
    }
    
    /*****
     * @param encrypt
     * @version 1.0.0
     */
    public final void setEncrypt(String encrypt)
    {
        this.encrypt = encrypt;
    }
    
    /*****
     * @version 1.0.0
     * @return channel
     */
    public final String getChannel()
    {
        return channel;
    }
    
    /*****
     * @param channel
     * @version 1.0.0
     */
    public final void setChannel(String channel)
    {
        if ("1".equals(channel)) // 苹果
        {
            this.channel = Channel.IOS.value();
        }
        else if ("2".equals(channel)) // 安卓
        {
            this.channel = Channel.ANDROID.value();
        }
        else if ("3".equals(channel)) // WEB
        {
            this.channel = Channel.WEB.value();
        }
        else
        {
            this.channel = channel;
        }
    }
    
    private enum Channel
    {
        ANDROID("Android"), IOS("IOS"), WEB("WEB");
        
        private String code;
        
        private Channel(String code)
        {
            this.code = code;
        }
        
        public String value()
        {
            return this.code;
        }
    }
    
    public String toString()
    {
        StringBuilder builder = new StringBuilder();
        builder.append("RequestBaseBean [channel=");
        builder.append(channel);
        builder.append(", encrypt=");
        builder.append(encrypt);
        builder.append(", pageNo=");
        builder.append(pageNo);
        builder.append(", pageSize=");
        builder.append(pageSize);
        builder.append(", locale=");
        builder.append(locale);
        builder.append("]");
        return builder.toString();
    }
}
